package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.product.domain.GoodsDirectory;
import com.ruoyi.product.service.IGoodsDirectoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 店铺目录Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/directory")
public class GoodsDirectoryController extends BaseController
{
    @Autowired
    private IGoodsDirectoryService goodsDirectoryService;

    /**
     * 查询店铺目录列表
     */
    @PreAuthorize(hasPermi = "product:directory:list")
    @GetMapping("/list")
    public AjaxResult list(GoodsDirectory goodsDirectory)
    {
        List<GoodsDirectory> list = goodsDirectoryService.selectGoodsDirectoryList(goodsDirectory);
        return AjaxResult.success(list);
    }

    /**
     * 导出店铺目录列表
     */
    @PreAuthorize(hasPermi = "product:directory:export")
    @Log(title = "店铺目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsDirectory goodsDirectory) throws IOException
    {
        List<GoodsDirectory> list = goodsDirectoryService.selectGoodsDirectoryList(goodsDirectory);
        ExcelUtil<GoodsDirectory> util = new ExcelUtil<GoodsDirectory>(GoodsDirectory.class);
        util.exportExcel(response, list, "店铺目录数据");
    }

    /**
     * 获取店铺目录详细信息
     */
    @PreAuthorize(hasPermi = "product:directory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(goodsDirectoryService.selectGoodsDirectoryById(id));
    }

    /**
     * 新增店铺目录
     */
    @PreAuthorize(hasPermi = "product:directory:add")
    @Log(title = "店铺目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsDirectory goodsDirectory)
    {
        return toAjax(goodsDirectoryService.insertGoodsDirectory(goodsDirectory));
    }

    /**
     * 修改店铺目录
     */
    @PreAuthorize(hasPermi = "product:directory:edit")
    @Log(title = "店铺目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsDirectory goodsDirectory)
    {
        return toAjax(goodsDirectoryService.updateGoodsDirectory(goodsDirectory));
    }

    /**
     * 删除店铺目录
     */
    @PreAuthorize(hasPermi = "product:directory:remove")
    @Log(title = "店铺目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsDirectoryService.deleteGoodsDirectoryByIds(ids));
    }
    /**
     * 获取店铺目录下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(GoodsDirectory goodsDirectory)
    {
        List<GoodsDirectory> list = goodsDirectoryService.selectGoodsDirectoryList(goodsDirectory);

        return AjaxResult.success(goodsDirectoryService.buildGoodsDirectoryTreeSelect(list));
    }
}
